{\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
{\fonttbl\f0\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue191;\red0\green0\blue255;\red102\green102\blue191;
\red0\green115\blue0;\red191\green0\blue0;\red96\green96\blue96;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural

\f0\fs18 \cf2 <PieceName>\cf0  : \cf2 ManticorePiece\cf0 \
\{\
	\cf3 classvar\cf0  <scoreIndex;\
	\cf3 var\cf0  scoreText;\
	\
	\cf3 var\cf0  osc;\
	\
	*new\
	\{\
		^\cf4 super\cf0 .new.init;\
	\}\
	\
	*initClass\
	\{\
		\cf2 Manticore\cf0 .registerPiece(\cf5 '\cf2 <PieceName>\cf5 '\cf0 );	\cf6 // register with Manticore\cf0 \
	\}\
	\
	init\
	\{\
		\cf2 Manticore\cf0 .group = \cf7 "MP"\cf0 ;\
		\
		osc = \cf2 List\cf0 .new;\
		\
		scoreIndex = 0;\
		\
		scoreText = [\
			\cf7 "score"\cf0 \
		];\
\
		\cf4 this\cf0 .setupOSClisteners;\
		\cf4 this\cf0 .storeSynthDefs;\
		\
		\cf2 OSCthulhu\cf0 .changePorts(57120);\
		\cf2 OSCthulhu\cf0 .login(\cf2 Manticore\cf0 .group);\
		\
		\cf6 // make the score buttons work\cf0 \
		\cf2 Manticore\cf0 .onScoreNext(\{\
			\cf2 OSCthulhu\cf0 .setSyncArg(\cf2 Manticore\cf0 .group++\cf7 "_Global"\cf0 , 0, (scoreIndex+1)%scoreText.size);\
		\});\
		\cf2 Manticore\cf0 .onScorePrevious(\{\
			\cf2 OSCthulhu\cf0 .setSyncArg(\cf2 Manticore\cf0 .group++\cf7 "_Global"\cf0 , 0, (scoreIndex-1)%scoreText.size);\
		\});\
		\
		\cf6 // args: scoreIndex, volume\cf0 \
		\cf2 OSCthulhu\cf0 .addSyncObject(\
			\cf2 Manticore\cf0 .group++\cf7 "_Global"\cf0 ,\
			\cf2 Manticore\cf0 .group,\
			\cf7 "glbl"\cf0 ,\
			[\
				0,		\cf6 // scoreIndex\cf0 \
				1.0		\cf6 // volume\cf0 \
			]\
		);\
	\}\
	\
	setupOSClisteners\
	\{\
		\cf6 // addSyncObject\cf0 \
		osc.add(\cf2 OSCthulhu\cf0 .onAddSyncObject(\cf5 \\addScore\cf0 , \{\cf3 |msg|\cf0 \
			\cf3 var\cf0  oscAddr, objName, group, subGroup, args;\
			\
			# oscAddr, objName, group, subGroup = msg;\
			args = msg.copyRange(4,msg.size-1);\
			\
			if(subGroup.asString == \cf7 "glbl"\cf0 ,\{\
				scoreIndex = args[0];\
				\cf2 Manticore\cf0 .updateScore(scoreText[scoreIndex]);\
			\});\
			\
		\})\
		);\
		\
		\cf6 // setSyncArg\cf0 \
		osc.add(\cf2 OSCthulhu\cf0 .onSetSyncArg(\cf5 \\updateScore\cf0 , \{\cf3 |msg|\cf0 \
			\cf3 var\cf0  oscAddr, objName, argIndex, argValue, group, subGroup;\
			\
			# oscAddr, objName, argIndex, argValue, group, subGroup = msg;\
			\
			if(subGroup.asString == \cf7 "glbl"\cf0 , \{\
				switch(\
					argIndex,\
					0, \{\
						\
						if(argValue != scoreIndex,\{\
							\cf6 // things that only change when the score does go here\cf0 \
						\});\
						\
						scoreIndex = argValue;\
						\cf2 Manticore\cf0 .updateScore(scoreText[scoreIndex]);\
					\}\
				)\
			\});\
		\})\
		);\
	\}\
	\
	free\
	\{\
		osc.collect(\{\cf3 |def|\cf0  def.free; \});\
		\cf2 OSCthulhu\cf0 .cleanup(\cf2 Manticore\cf0 .group);\
	\}\
	\
	storeSynthDefs\
	\{\
		\
	\}\
	\
	getInterface\
	\{\cf3 |p|\cf0 \
		\cf3 var\cf0  scrollView;\
		\
		scrollView = \cf2 ScrollView\cf0 ();\
		\
		^p.layout_(\cf2 HLayout\cf0 ( [scrollView, stretch:1] ));\
	\}\
\}}